package com.hy.demo.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.hy.demo.R;

public class BottomNavigationView extends com.google.android.material.bottomnavigation.BottomNavigationView {
    public BottomNavigationView(@NonNull Context context) {
        this(context, null);
    }

    public BottomNavigationView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, R.attr.bottomNavigationStyle);
    }

    public BottomNavigationView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        closeTip();
    }

    private View.OnLongClickListener closeTipListener;

    public void closeTip() {
        if (closeTipListener == null) {
            closeTipListener = new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    return true;
                }
            };
        }
        if (getChildCount() > 0) {
            View v = getChildAt(0);
            if (v instanceof ViewGroup) {
                ViewGroup group = (ViewGroup) v;
                int childCount = group.getChildCount();
                if (childCount > 0) {
                    for (int j = 0; j < childCount; j++) {
                        group.getChildAt(j).setOnLongClickListener(closeTipListener);
                    }
                }
            }
        }
    }


}
